<template>
    <div>
        <div class="art_info">
            <p class="title">标题</p>
            <div class="enter">
                <input type="text" v-model="form.title" placeholder="请输入标题" placeholder-class="placeholder">
            </div>
            <p class="title">内容</p>
            <div class="enter">
                <textarea v-model="form.content" placeholder="正文内容" placeholder-class="placeholder"></textarea>
            </div>
        </div>
        <div class="submit" @click="submit">保存</div>
    </div>
</template>

<script>
import { editCodeContents, getCodeContents } from '@/request/house'
export default {
    name: "",
    components: {},
    data() {
        return {
            codeId: '',
            artId: '',
            form: {
                title: '',
                content: '',
            }
        }
    },
    onLoad({ codeId, id }) {
        this.codeId = codeId
        this.artId = id || void 0
        if(this.artId) {
            this.getArtDetail()
        }
    },
    methods: {
        getArtDetail() {
            getCodeContents({
                codeId: this.codeId,
                id: this.artId
            }).then(res => {
                let data = res.data.list[0]
                this.form.title = data.title
                this.form.content = data.content
            })
        },
        submit() {
            if(!this.form.title) return this.$interact.toast('请输入标题')
            if(!this.form.content) return this.$interact.toast('请输入内容')
            console.log(this.form);
            editCodeContents({
                ...this.form,
                id: this.artId || void 0,
                codeId: this.codeId,
            }).then(res => {
                this.$interact.modal(res.msg).then(action => {
                    this.$navigate.back()
                    if(this.$prePage()) this.$prePage().onRefresh();
                })
            })
        }
    }
}
</script>
<style lang="less" scoped>
@import "~@/styles/cell.less";
.art_info{
    padding: 20rpx;
    .title{
        height: 60rpx;
        line-height: 60rpx;
        font-size: 28rpx;
    }
    .enter{
        min-height: 80rpx;
        background: #fff;
        box-shadow: 0 0 10rpx #ccc;
        input{
            width: 100%;
            height: 80rpx;
            line-height: 80rpx;
            padding-left: 10rpx;
        }
        textarea {
            width: 100%;
            font-size: 28rpx;
            padding: 10rpx;
            height: 800rpx;
        }
    }
}

.submit{
    width: 690rpx;
    height: 90rpx;
    background: @mainColor;
    margin: 60rpx auto;
    .align(center);
    color: #fff;
    font-size: 34rpx;
    font-weight: bold;
    border-radius: 10rpx;
}

</style>